package com.cn.hjsj.appInterface.appImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.cn.hjsj.appInterface.appService.AppBrandWebsiteService;
import com.cn.hjsj.pojo.BrandWebsite;
import com.cn.hjsj.service.IBrandWebsiteService;
import com.cn.hjsj.util.log.LogUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Component("appBrandWebsiteImpl")
public class AppBrandWebsiteImpl implements AppBrandWebsiteService {
	@Resource(name="brandWebsiteService")
	private IBrandWebsiteService brandWebsiteService;
	@Override
	public Map<String, Object> getBrand(JSONObject object) {
		// TODO Auto-generated method stub
		Map<String, Object>  map=new HashMap<String,Object>(),
				mapOne=new HashMap<String,Object>(),
				maps=new HashMap<String,Object>(),
				mapTwo=new HashMap<String,Object>();
		JSONArray brand = new JSONArray();
		try{
			//获取 storeList 列表
			Integer page = object.getInt("page");					
            Integer pageNo = object.getInt("linage");             		
            page = (page - 1) * pageNo;
            if(page<0){
                map.put("code", "30005");
                map.put("mes", "page有误");
                return map;
            }
            maps.put("startRow", page);
            maps.put("pageSize", pageNo);
            List<BrandWebsite> brandWebsiteList = brandWebsiteService.getList(maps);
            int count = brandWebsiteService.getCount(maps);
            if(count>0){
				for (int i=0;i<brandWebsiteList.size();i++){
						mapOne.put("brandName", brandWebsiteList.get(i).getBrandname());
						mapOne.put("url", brandWebsiteList.get(i).getUrl());	
						brand.add(mapOne);
					}
				LogUtil.info("/AppBrandWebsiteImpl/getBrand:调用成功");
				mapTwo.put("brandList", brand);
				mapTwo.put("count", count);
				map.put("code", "10000");
				map.put("data", mapTwo);
				map.put("mes", "调用成功");						
			}else{
				LogUtil.info("/AppBrandWebsiteImpl/getBrand:调用成功");
				mapTwo.put("serviceType", brand);
				mapTwo.put("count", count);
				map.put("code", "10000");
				map.put("data", mapTwo);
				map.put("mes", "调用成功,数据库中无数据");
			}
			return map;
            
		}catch(Exception e){
			LogUtil.error("/AppBrandWebsiteImpl/getBrands:解析参数异常！"+e.getMessage());
			map.put("code", "30000");
			map.put("mes", "参数列表初始化错误，可能不是合法的JSON数据格式！");
		
			return map;
		}
	}

}
